package edu.auctionmart



import edu.auctionmart.Profile;
import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Profile)
class ProfileTests {

    void testProfile() {
		
		Location testLocation = new Location(name: "Russell Gillen", addressLine: "50 USM Street", zipCode: "04103", town: "Portland", state: "ME")

		//Invalid phone number
       Profile testProfile = new Profile(contactPhoneNumber: 103, contactEmail: "rhgillen@gmail.com")
	   testProfile.addToAddresses(testLocation)
	   testProfile.validate()
	   assert(testProfile.hasErrors() == true)
	   
	   testProfile = new Profile(contactPhoneNumber: 2074503879, contactEmail: "rhgillen@gmail.com")
	   testProfile.addToAddresses(testLocation)
	   testProfile.validate()
	   assert(testProfile.hasErrors() == false)
	   
	   //Malformed e-mail
	   testProfile = new Profile(contactPhoneNumber: 2074503879, contactEmail: "rhgillenagmail.com")
	   testProfile.addToAddresses(testLocation)
	   testProfile.validate()
	   assert(testProfile.hasErrors() == true)
	   
	   //no locations, can create a profile with no locations
	   testProfile = new Profile(contactPhoneNumber: 2074503879, contactEmail: "rhgillen@gmail.com")
	   testProfile.validate()
	   assert(testProfile.hasErrors() == false)
    }
}
